// packageA/activityDetails/activityDetails.js
import {getTopic} from "../../api/news.js"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    $https:getApp().globalData.$https,
     swcurrent1:0,
     swcurrent2:0,
     swcurrent3:0,
     swmax1:2,
     swmax2:2,
     swmax3:2,
     id:undefined,
     news:[],
     topic:{
      highlightList:[],
      imagesList:[],
      videosList:[]
     }
     
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id:options.id
    })
    this.getTopic()
  },
  async getTopic(){
    var id = this.data.id
    var res = await getTopic(id)
    console.log(res)
    this.setData({
      news:res.news,
      topic:res.topic
    })
  },
  jumpnews(e){
    var {id} = e.currentTarget.dataset
    wx.navigateTo({
      url: '/packageA/Newsdetail/Newsdetail?id=' + id,
    })
  },
  chbsw(e){
    console.log(e,234)
    var {dataname} = e.currentTarget.dataset
    console.log(dataname)
    
    this.setData({
      [dataname]:e.detail.current
    })
  },
  chbsw(e){
    var  {swid,isevent,max }= e.currentTarget.dataset
    var currentIndex = this.data[swid]
    console.log(currentIndex)
    if(isevent==='prev'){ //前一个
      if(currentIndex==0){
        this.setData({
          [swid]:max-1
        })
      }else{
        this.setData({
          [swid]: currentIndex-1
        })
      }
    }else if(isevent === "next"){ //下一个
      console.log(currentIndex,max)
      if(currentIndex==(max-1)){
        this.setData({
          [swid]:0
        })
      }else{
        this.setData({
          [swid]: currentIndex+1
        })
      }

    }
  },
  baoming(){
    if(this.data.topic.isEnroll == 1){
      wx.navigateTo({
        url: '/packageA/signUp/signUp?id='+this.data.id,
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})